#
# @lc app=leetcode.cn id=7 lang=python
#
# [7] 整数反转
#

# @lc code=start
class Solution(object):
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        if x == 0 or x <= -2**31 or x > 2**31-1:
            return 0
        elif x > 0:
            x_string_reverse = str(x)[::-1]
            pre_result =  int(x_string_reverse)
            if pre_result < 2**31:
                return pre_result
            else:
                return 0
        else:
            x_string_reverse = str(abs(x))[::-1]
            pre_result = int(x_string_reverse)
            if pre_result > 2**31:
                return 0
            else:
                return -int(x_string_reverse)
            
# @lc code=end

if __name__ == "__main__":
    solution = Solution()
    print(solution.reverse(-1563847412))
